import java.util.ArrayList;
import java.util.Arrays;

public class Solution414 {
    public int thirdMax(int[] nums) {
        Arrays.sort(nums);
        if(nums.length<3) return nums[nums.length-1];
        ArrayList<Integer> arrayList=new ArrayList<>();
        for (int i = 0; i < nums.length; i++) {
            if(arrayList.indexOf(nums[i])==-1){
                arrayList.add(nums[i]);
            }
        }
        if(arrayList.size()<3) return arrayList.get(arrayList.size()-1);
        return arrayList.get(arrayList.size()-3);

    }

    public static void main(String[] args) {
        Solution414 solution414=new Solution414();
        System.out.println(solution414.thirdMax(new int[]{
                2, 1,1
        }));
    }
}
